var e = getApp(), t = e.requirejs("core"), i = e.requirejs("foxui"), a = e.requirejs("jquery");

Page({
    data: {
        member: {},
        binded: !1,
        endtime: 0,
        postData: {},
        submit: !1,
        subtext: "立即注册",
        smsimgcode: "",
        opensms:"",
        verifycode_img: ""
    },
    onLoad: function(i) {
        var a=this;
        var scene = decodeURIComponent(i.scene)
        if(i.scene){
           var scene = decodeURIComponent(i.scene)
           //let mobile=scene.split("-")[0];
           let tuisn=scene;
            var postData=a.data.postData;
            postData.tuisn=tuisn;
           a.setData({tuisn: tuisn,postData:postData})
           console.log(a.data);
        }else{
          a.setData({tuisn: ''})

          //a.setData({live_id: 245,})
        }


        var o=this;

         t.get("wxAppSetting", {}, function(e) {
            var n = e.sysset;
            o.setData({
                shop_logo: n.shoplogo,
                shop_name: n.shopname
            });
        });
        e.url(i), t.loading(), this.getInfo();
    },
    getInfo: function() {
        var e, i = this;

        t.get("wxapp/register", {}, function(t) {
            /*if (t.error) wx.redirectTo({
                url: "/pages/member/index/index"
            }); else {

            }*/
            if (t.member.mobile) {
                wx.switchTab({
                    url: "/pages/index/index"
                });
                /* wx.navigateBack({
                    changed: !0
                })*/
            }
            else {
                var a = {
                    member: t.member,
                    binded: t.binded,
                    endtime: t.endtime,
                    show: !0,
                    smsimgcode: t.smsimgcode,
                    opensms: t.opensms,
                    verifycode_img: t.verifycode_img
                };
                a.postData = {
                    realname: '',
                    mobile: '',
                    code: "",
                    tuisn: i.data.tuisn,
                    password: "",
                    password1: ""
                }, i.setData(a), t.endtime > 0 && i.endTime(), e = t.binded ? "快速注册" : "快速注册",
                wx.setNavigationBarTitle({
                    title: e
                });

            }
        }, !0, !0, !0);
    },
    endTime: function() {
        var e = this, t = e.data.endtime;
        if (t > 0) {
            e.setData({
                endtime: t - 1
            });
            setTimeout(function() {
                e.endTime();
            }, 1e3);
        }
    },
    inputChange: function(e) {
        var i = this.data.postData, s = t.pdata(e).type, o = e.detail.value;
        i[s] = a.trim(o), this.setData({
            postData: i
        });
    },
    getCode: function(e) {
        var s = this;
        if (!(s.data.endtime > 0)) {
            var o = s.data.postData.mobile;
            if (a.isMobile(o)) {
                if (1 == s.data.smsimgcode) {
                    var m = s.data.postData.verifyImg;
                    if (null == m) return void i.toast(s, "请填写图形验证码");
                }
                t.get("sms/changemobile", {
                    mobile: o,
                    verifyImgCode: m,
                    smsimgcode: s.data.smsimgcode
                }, function(e) {
                    null == e.error ? (i.toast(s, "短信发送成功"), s.setData({
                        endtime: 60
                    }), s.endTime()) : i.toast(s, e.message);
                }, !0, !0, !0);
            } else i.toast(s, "请填写正确的手机号");
        }
    },
    submit: function(e) {
        //i.toast(this, '注册成功' , 300000,'green');return;
        if (!this.data.submit) {
            var s = this, o = this.data.postData;
           // a.isMobile(o.mobile) ? 5 == o.code.length ? o.password && "" != o.password ? o.password1 && "" != o.password1 ? o.password == o.password1 ? (this.setData({
            console.log(o);
           // return false;
           o.realname!='' ? a.isMobile(o.mobile) ?  o.password && "" != o.password ? o.password1 && "" != o.password1 ? o.password == o.password1 ? (this.setData({
                submit: !0,
                subtext: "正在注册..."
            }), t.post("wxapp/regsubmit", o, function(e) {
                 0 != e.error ? (i.toast(s, e.message),
                void s.setData({
                    submit: !1,
                    subtext: "立即注册"
                })) : (i.toast(s, '注册成功',1500,'#BD081B'),wx.navigateTo({
                    url: "/pages/auth/login/index"
                }));;
                /*t.confirm(e.message, function() {
                    o.confirm = 1, t.post("member/bind/submit", o, function(e) {
                        e.error > 0 ? i.toast(s, e.message) : wx.navigateBack(), s.setData({
                            submit: !1,
                            subtext: "立即登录",
                            "postData.confirm": 0
                        });
                    }, !0, !0, !0);
                });*/
            }, !0, !0, !0)) : i.toast(this, "两次输入的密码不一致") : i.toast(this, "请确认登录密码") : i.toast(this, "请填写登录密码")  :  i.toast(this, "请填写正确的手机号") :  i.toast(this, "请填写您的姓名");
        }
    },
    imageChange: function() {
        var e = this;
        t.get("member/bind/imageChange", {}, function(t) {
            e.setData({
                verifycode_img: t.verifycode_img
            });
        });
    }
});